﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Runtime.Serialization;

namespace NGinnBPM.Runtime
{
    [AttributeUsage(AttributeTargets.Property)]
    public class TaskParameterAttribute : Attribute
    {
        public bool Required = true;
        public bool DynamicAllowed = true;
        public bool IsInput;
    }


    [Serializable]
    [DataContract]
    public class TaskParameterInfo
    {
        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public bool Required { get; set; }

        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public bool DynamicAllowed { get; set; }

        private string _paramTypeName;
        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public string ParameterTypeName 
        {
            get { return _paramTypeName; }
            set { _paramTypeName = value; _paramType = Type.GetType(value, false); }
        }

        private Type _paramType;

        [IgnoreDataMember]
        public Type ParameterType
        {
            get { return _paramType; }
            set 
            { 
                _paramType = value;
                _paramTypeName = value.FullName;
            }
        }

        [DataMember(IsRequired = false)]
        public bool IsInput { get; set; }
        
        public TaskParameterInfo()
        {
        }

        public TaskParameterInfo(string paramName, Type paramType, bool required, bool isInput, bool dynamicAllowed)
        {
            Name = paramName;
            ParameterType = paramType;
            ParameterTypeName = paramType.FullName;
            IsInput = isInput;
            Required = required;
            DynamicAllowed = dynamicAllowed;
        }
    }
}
